<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="time.jsp" %>
<%@ page import="domain.User" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户登陆</title>
</head>
<body style="text-align:center;">
<%!
    public String Uname(String uP, String uL) {
        if (uL != null) {
            return uL;
        } else {
            return uP == null ? "" : uP;
        }
    }
%>
<%
    Object obj = session.getAttribute("user");
    String unameP = (String) session.getAttribute("usernamePrepared");
    String unameL = (String) request.getParameter("usernameLogined");
    String UName = Uname(unameP, unameL);
    System.out.println("unameL:" + unameL);
    if (null == obj) {
%>
<h2>登录页面</h2>
<form action="LoginServlet" method="post">
    <table align="center">
        <tr>
            <td>
                用户名：
            </td>
            <td style="text-align:center"><input type="text" size="21" name="username" value="<%=UName%>"/></td>
        </tr>
        <tr>
            <td>
                密&nbsp;&nbsp;&nbsp;&nbsp;码：
            </td>
            <td><input type="password" size="21" name="password"/></td>
        </tr>
    </table>
    <table align="center" cellspacing="5">
        <tr>
            <td><input type="submit" name="submit" value="登录"/></td>
            <td><input type="reset" name="reset" value="清空"/></td>
        </tr>
    </table>
</form>
<a href="register.jsp" name="register">跳转注册</a>
<%
} else {
%>
<%
    User u = (User) obj;
%>
用户:<%=u.getUsername() %><br/>您已经登录，无需再登录
<br/><a href="exit.jsp" name="exit">退出登录</a>
<br/><a href="login_success.jsp" name="success">返回</a>
<%}%>
</body>
</html>